#include<ui.h>

//绘制按键
static int DefaultOnDraw(struct Button* ptButton, PDispBuffer ptDispBuffer)
{
	
	DrawRegion(&ptButton->tRegion, BUTTON_DEFAULT_COLOR);
	
	DrawTextInRegionCenter(ptButton->name, &ptButton->tRegion, BUTTON_TEXT_COLOR);

	FlushDisplayRegion(&ptButton->tRegion, ptDispBuffer);

	return 0;
}

//按键按下后变化
static int DefaultOnPressed(PButton ptButton, PDispBuffer ptDispBuffer, PInputEvent ptInputEvent)
{
	unsigned int dwColor = BUTTON_DEFAULT_COLOR;
	
	ptButton->status = !ptButton->status;
	if(ptButton->status)
	{
		dwColor = BUTTON_PRESSED_COLOR;
	}
		
	DrawRegion(&ptButton->tRegion, dwColor);
	
	DrawTextInRegionCenter(ptButton->name, &ptButton->tRegion, BUTTON_TEXT_COLOR);

	FlushDisplayRegion(&ptButton->tRegion, ptDispBuffer);
	
	return 0;
}


void InitButton(PButton ptButton, char *name, PRegion ptRegion, ONDRAW_FUNC OnDraw, ONPRESSED_FUNC OnPressed)
{
	ptButton->name = name;
	ptButton->status = 0;
	ptButton->tRegion = *ptRegion;
	ptButton->OnDraw = OnDraw ? OnDraw : DefaultOnDraw;
	ptButton->OnPressed = OnPressed ? OnPressed : DefaultOnPressed;

}

